<template>
  <div class="product">
    <!-- 头部区域 -->
    <div class="header">
      <span>物品类型</span>
      <el-select v-model="productType" clearable placeholder="请选择栏目">
        <el-option
          v-for="item in options"
          :key="item.id"
          :label="item.name"
          :value="item.name"
        >
        </el-option>
      </el-select>
      <span>关键字</span>
      <el-input
        v-model="productName"
        style="width: 240px"
        placeholder="请输入物品关键字"
        clearable
      />
      <el-button type="primary" style="margin-left: 15px" @click="findapply"
        >查询</el-button
      >
    </div>
    <!-- 表格内容展示区 -->
    <div class="table-content" style="width: 100%">
      <el-table :data="tableData.list" stripe style="width: 100%">
        <el-table-column type="index" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="baseUser.realname" label="申请人" align="center">
        </el-table-column>
        <el-table-column prop="asset.code" label="物品编号" align="center">
        </el-table-column>
        <el-table-column prop="asset.name" label="物品名称" align="center">
        </el-table-column>
        <el-table-column prop="asset.type" label="物品类型" align="center">
        </el-table-column>
        <el-table-column prop="type" label="申请类别" align="center">
        </el-table-column>
        <el-table-column prop="asset.brand" label="品牌" align="center">
        </el-table-column>
        <el-table-column prop="num" label="数量" align="center">
        </el-table-column>
        <el-table-column
          prop="applyforTime"
          label="领用日期"
          align="center"
          :formatter="dateFormat"
        >
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center">
          <template slot-scope="scope">
            <el-tag>{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="操作" align="center">
          <template v-slot="scope">
            <el-button type="text" @click="restore(scope.row)">归还</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="归还确认"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose"
      >
        <el-form :model="form">
          <el-form-item label="活动名称" :label-width="formLabelWidth">
            <el-input v-model="form.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item label="活动区域" :label-width="formLabelWidth">
            <el-select v-model="form.region" placeholder="请选择活动区域">
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import qs from "qs";
import moment from "moment";
export default {
  data() {
    return {
      options: [],
      productType: "",
      productName: "",
      apply: {
        page: 1,
        pageSize: 10,
        applyforType: "领用",
        type: "",
        name: "",
      },
      tableData: [],
      dialogVisible: false,
      form:{
        name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
      },
      formLabelWidth: '120px'
    };
  },
  methods: {
    findProductType() {
      request.get("/assetType/findAll").then((res) => {
        this.options = res.data;
        // console.log(this.options);
        // console.log(res);
      });
    },
    findAllList() {
      const data = qs.stringify(this.apply);
      request.post("/applyfor/pageQuery", data).then((res) => {
        // console.log(res.data.list);
        this.tableData = res.data;
      });
    },
    dateFormat(row, column, cellValue, index) {
      const daterc = row[column.property];
      return moment(daterc).format("YYYY年M月DD日HH:mm");
    },
    findapply() {
      for (let key in this.apply) {
        if (this.apply[key] == "") {
          delete this.apply[key];
        }
      }
      this.apply.type = this.productType;
      this.apply.name = this.productName;
      let Productdata = qs.stringify(this.apply);
      request.post("/applyfor/pageQuery", Productdata).then((res) => {
        // console.log(res);
        this.tableData = res.data;
      });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    restore(row) {
      // this.tableData = row;
      this.dialogVisible = true;
    },
  },
  created() {
    this.findProductType();
    this.findAllList();
  },
  mounted() {},
};
</script>
<style scoped>
/* 设置header的样式 */
.product {
  background-color: #fff;
  border-radius: 8px;
  padding: 15px;
}
.header {
  line-height: 40px;
}
.header span {
  margin: 10px;
  font-weight: 600;
  color: #666;
}
.table-content {
  margin-top: 15px;
}
/* 分页区域的样式 */
</style>
